package com.itheima.web;

import com.itheima.servcie.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {
    @Autowired
    private MessagesService messagesService;

    @GetMapping("/userinfo")
    private ResponseEntity userInfo(String huanxinId){
        return ResponseEntity.ok(messagesService.getHuanxinUser(huanxinId));
    }

    /**
     * 公告列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize){
        return ResponseEntity.ok(messagesService.announcements(page, pagesize));
    }

    /**
     * 添加好友
     * @param map
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map<String, Integer> map){
        messagesService.addFriend(map.get("userId"));
        return ResponseEntity.ok(null);
    }

    /**
     * 好友列表
     * @param page
     * @param pagesize
     * @param keyword
     * @return
     */
    @GetMapping("/contacts")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   String keyword){
        return ResponseEntity.ok(messagesService.getFriendsList(page, pagesize, keyword));
    }

    /**
     * 喜欢列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        return ResponseEntity.ok(messagesService.loves(page, pagesize));
    }

    /**
     * 评论列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize){
        return ResponseEntity.ok(messagesService.comments(page, pagesize, 2));
    }

    /**
     * 喜欢列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize){
        return ResponseEntity.ok(messagesService.comments(page, pagesize, 1));
    }
}
